package com.boyu.common.interceptor;

import com.boyu.common.SystemConst;
import com.boyu.common.config.BackendRoutes;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
 * Created by Administrator on 2017/4/27.
 */
public class AdminAuthInterceptor implements Interceptor {
	@Override
	public void intercept(Invocation inv) {
		System.out.println("Before method invoking");
		inv.invoke();
		Controller controller = inv.getController();
		String contextPath = inv.getController().getRequest().getContextPath();
		Object attribute = controller.getSession().getAttribute(SystemConst.ADMIN_USER_SESSION);
		if (attribute == null) {
			controller.redirect(contextPath + "/" +BackendRoutes.BACKEND + "/toLogin");
		}
		System.out.println("After method invoking");
	}
}
